/*
 * @(#)MessagesUtil.java
 *
 * Copyright 2012 by ShenY BIS, All rights reserved.
 */

package com.bis.framework.util.common;

import java.util.Locale;

import org.springframework.context.MessageSource;

/**
 * MessagesUtil
 * 
 * @author BIS 2012-12-24
 */
public class MessagesUtil
{

    /**
     * getMessageSource
     * @Description:
     * @return
     */
    public static MessageSource getMessageSource()
    {
        MessageSource msgResource = (MessageSource) SpringContextUtil.getCtx().getBean("messageSource");
        return msgResource;
    }

    /**
     * getMessage
     * @Description:
     * @param key
     * @param defaultKey
     * @param args
     * @return
     */
    public static String getMessage(String key, String defaultKey, Object[] args)
    {
        return getMessage(key, args, getMessageSource().getMessage(defaultKey, null, Locale.getDefault()), Locale.getDefault());
    }

    /**
     * getMessage
     * @Description:
     * @param key
     * @param args
     * @param locale
     * @return
     */
    public static String getMessage(String key, Object[] args, Locale locale)
    {
        return getMessageSource().getMessage(key, args, Locale.getDefault());
    }

    /**
     * getMessage
     * @Description:
     * @param key
     * @param args
     * @param defaultMessage
     * @param locale
     * @return
     */
    public static String getMessage(String key, Object[] args, String defaultMessage, Locale locale)
    {
        return getMessageSource().getMessage(key, args, defaultMessage, Locale.getDefault());
    }
}
